package com.prs.crm.action.gantt;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.Util;
import org.w3c.dom.Document;

import com.prs.crm.action.XMLExportAction;
import com.prs.crm.util.GanttExport;
import com.prs.crm.vo.gantt.GanttTask;
import com.prs.crm.vo.gantt.PredecessorTask;

/**
 * 甘特测试
 * 从XMLExportAction继承
 * @author chenzhi
 *
 */
public class TestAction extends XMLExportAction{

	private static final long serialVersionUID = 1L;
	
	private Document document;
	
	private GanttExport ganttExportUtil;
	
	public void setDocument(Document document) {
		this.document = document;
	}

	public Document getDocument() {
		return document;
	}
	
	public void setGanttExportUtil(GanttExport ganttExportUtil) {
		this.ganttExportUtil = ganttExportUtil;
	}

	public GanttExport getGanttExportUtil() {
		return ganttExportUtil;
	}

	@Action("test")
	public String test()
	{
		return SUCCESS;
	}

	@Action(value="loadGanttData",results={@Result(name="success",type="xslt",params={"exposedValue","document","location","/WEB-INF/xml.xsl"})})
	public String execute() throws Exception
	{
		//根任务，该任务不会显示在界面上
		GanttTask task = new GanttTask(0,"住宅建设");
		
		task.setStart(Util.formatDateStr("2004-01-01T08:00:00", "yyyy-MM-dd'T'HH:mm:ss"));
		task.setFinish(Util.formatDateStr("2004-07-30T17:00:00", "yyyy-MM-dd'T'HH:mm:ss"));
		task.setSummary(true);
		
		GanttTask task1 = new GanttTask(1,"单户住宅: 建筑师设计(280 平方米，并带有完整地下室");
		task1.setStart(Util.formatDateStr("2004-01-01T08:00:00", "yyyy-MM-dd'T'HH:mm:ss"));
		task1.setFinish(Util.formatDateStr("2004-07-30T17:00:00", "yyyy-MM-dd'T'HH:mm:ss"));
		task1.setSummary(true);
		task.addChild(task1);
		
		GanttTask task2 = new GanttTask(2,"一般要求");
		task2.setStart(Util.formatDateStr("2004-01-01T08:00:00", "yyyy-MM-dd'T'HH:mm:ss"));
		task2.setFinish(Util.formatDateStr("2004-01-05T17:00:00", "yyyy-MM-dd'T'HH:mm:ss"));
		task2.setMilestone(true);
		task1.addChild(task2);
/*		
		GanttTask task3 = new GanttTask(3,"一般要求");
		task3.setStart(Util.formatDateStr("2004-01-01T08:00:00", "yyyy-MM-dd'T'HH:mm:ss"));
		task3.setFinish(Util.formatDateStr("2004-01-05T17:00:00", "yyyy-MM-dd'T'HH:mm:ss"));
		task3.setMilestone(true);
		task1.addChild(task3);
		
		GanttTask task4 = new GanttTask(4,"task4");
		task4.setStart(Util.formatDateStr("2004-01-06T08:00:00", "yyyy-MM-dd'T'HH:mm:ss"));
		task4.setFinish(Util.formatDateStr("2004-01-09T17:00:00", "yyyy-MM-dd'T'HH:mm:ss"));
		task4.setPercentComplete(30);		
		PredecessorTask pt = new PredecessorTask(2,PredecessorTask.TYPE_FS);
		List<PredecessorTask> pts = new ArrayList<PredecessorTask>();
		pts.add(pt);
		task4.setPredecessorTasks(pts);
		task.setMilestone(true);
		task4.setLinkUrl("/oa/viewAffiche");
		task1.addChild(task4);
		
		GanttTask task5 = new GanttTask(5,"task5");
		task5.setStart(Util.formatDateStr("2004-01-06T08:00:00", "yyyy-MM-dd'T'HH:mm:ss"));
		task5.setFinish(Util.formatDateStr("2004-01-09T17:00:00", "yyyy-MM-dd'T'HH:mm:ss"));
		PredecessorTask pt5 = new PredecessorTask(3,PredecessorTask.TYPE_SF);
		PredecessorTask pt52 = new PredecessorTask(2,PredecessorTask.TYPE_FS);
		List<PredecessorTask> pt5s = new ArrayList<PredecessorTask>();
		pt5s.add(pt5);
		pt5s.add(pt52);
		task5.setPredecessorTasks(pt5s);
//		task5.setSummary(true);
		task1.addChild(task5);*/
		
		
		document = this.ganttExportUtil.exportXML(task);
		
		/**
		 * 必须调用
		 */
		this.prepareExport();
		return SUCCESS;
	}

	
}
